Public View

Hello,

What would be the best way to change all views that have been made public within the database so anyone can modify those views (Delete, etc.) My goal is only to change public views and leave private views alone. Any help would be appreciated.

-Jim
SystemAdmin - Tue Jan 08 22:35:16 EST 2013

Re: Public View
llandale - Wed Jan 09 09:14:07 EST 2013

"Public"/"Private" settings are inadequate. When you create a view only the creator has modify rights; "Public" provides universal "R", "Private" provides universal "None". It is thus a good idea after creating a view, to right away Manage Views and provide more suitable access (which becomes shown as "Custom").

To answer your question, the DOORS super-user "Administrator" will need to plow through the views and provide "Everyone else" "RMCD" or "RMCDA" access. That is not hard with a script.

It seems better to me though to just change the view to have "Inherited" access.

Better still would be for there to be a set of Project approved views that only the Project admins may modify.

-Louie

Re: Public View
SystemAdmin - Wed Jan 09 09:43:24 EST 2013

Hello,

I found the below code on the internet and made modifications to it. Does anyone see logic errors? Thank you.

-Jim
 

// List Public Views
 
/*
    Lists public views found in modules.

        Reports public views found in modules together with the owner
        and their email address.

        24-MAY-2011             Tony Goodman
*/
 
pragma runLim, 0
 
DB  dbMain      = null
DBE dbeResults  = null
 
Buffer buf = create
 
/*********************************
        getAccessRecord
*********************************/
string getAccessRecord(AccessRec ar)
{
        string r = ((read ar)    ? "R" : "")
        string m = ((modify ar)  ? "M" : "")
        string c = ((create ar)  ? "C" : "")
        string d = ((delete ar)  ? "D" : "")
        string a = ((control ar) ? "A" : "")
 
        string accessStr =  r m c d a ""
 
        if (null accessStr){accessStr = "None"}
 
        return(accessStr)
}
 
/*********************************
        isPublic
*********************************/
bool isPublic(View v, string &uName)
{
        AccessRec ar = null
        int count = 0
        bool def = false
 
        for ar in v do
        {
                //if no user or group assigned to AR, then must be the default "Everyone else" group
                uName = username ar
 
        if(null uName) 
                {
                        uName = "Administrator"
 
            if(getAccessRecord(ar) != "None"){def = true}
                }
        }
 
        return(def)
}
 
/*********************************
        getPublicViews
*********************************/
void getPublicViews(string mName, Buffer resBuf)
{
        Module m = null
        string vn = ""
        string uName = ""
        bool noneFound = true
 
        m = read(mName, false)
 
        if (null m)
        {
                resBuf += "ERROR: Failed to open module " mName ".\n"
                return
        }
 
        (current ModuleRef__) = m
 
        for vn in views m do
        {
                if (isPublic(view vn, uName))
                {
                        resBuf += name(m) " has public view \"" vn "\" owned by " uName ".\n"
                        noneFound = false
                        
                        View v = view vn
                        unsetAll (v)    
                        set (v, control | delete, "") // give everyone control permissions
                }
        }
 
        if (noneFound)
        {
                resBuf += name(m) " does not have any public views.\n"
        }
 
        close(m)
}
 
/*********************************
        doRun
*********************************/
void doRun(DB db)
{
        Item i
        setempty(buf)
        int pCount = 0
        int pLimit = 0
 
        for i in current Folder do
        {
                if (type(i) != "Formal") continue
 
                pLimit++
        }
 
        if (pLimit == 0)
        {
                buf += "No modules found.\n"
        }
        else
        {
                //buf += pLimit " modules found.\n"
 
                if (!confirm("You are about to search for public views in " pLimit " modules\nAre you sure you want to continue?"))
                {
                        buf += "Command aborted by user.\n"
                }
                else
                {
                        progressStart(dbMain, "Checking modules", "Checking modules", pLimit)
 
                        for i in current Folder do
                        {
                                if (type(i) != "Formal") continue
 
                                pCount++
                                progressRange("Checking module " pCount " of " pLimit ".", pCount, pLimit)
 
                                getPublicViews(fullName(i), buf)
                        }
 
                        progressStop()
                }
        }
 
        set(dbeResults, buf)
}
 
/*********************************
        listPublicViews
*********************************/
void listPublicViews()
{
        dbMain = create(dbExplorer, "List Public Views", styleCentered|styleFloating)
 
        label(dbMain, "This utility allows you identify public views, and their owners, contained in modules below the current folder.")
 
        field(dbMain, "Folder:", fullName(current Folder), 50, true)
 
        dbeResults = text(dbMain, "Results:", "", 600, 150, true)
 
        apply(dbMain, "Run", doRun)
 
        realize(dbMain)
 
        show(dbMain)
}
 
/*********************************
        MAIN
*********************************/
listPublicViews()

Re: Public View
llandale - Wed Jan 09 16:52:00 EST 2013

SystemAdmin - Wed Jan 09 09:43:24 EST 2013

Hello,

I found the below code on the internet and made modifications to it. Does anyone see logic errors? Thank you.

-Jim
 

// List Public Views
 
/*
    Lists public views found in modules.

        Reports public views found in modules together with the owner
        and their email address.

        24-MAY-2011             Tony Goodman
*/
 
pragma runLim, 0
 
DB  dbMain      = null
DBE dbeResults  = null
 
Buffer buf = create
 
/*********************************
        getAccessRecord
*********************************/
string getAccessRecord(AccessRec ar)
{
        string r = ((read ar)    ? "R" : "")
        string m = ((modify ar)  ? "M" : "")
        string c = ((create ar)  ? "C" : "")
        string d = ((delete ar)  ? "D" : "")
        string a = ((control ar) ? "A" : "")
 
        string accessStr =  r m c d a ""
 
        if (null accessStr){accessStr = "None"}
 
        return(accessStr)
}
 
/*********************************
        isPublic
*********************************/
bool isPublic(View v, string &uName)
{
        AccessRec ar = null
        int count = 0
        bool def = false
 
        for ar in v do
        {
                //if no user or group assigned to AR, then must be the default "Everyone else" group
                uName = username ar
 
        if(null uName) 
                {
                        uName = "Administrator"
 
            if(getAccessRecord(ar) != "None"){def = true}
                }
        }
 
        return(def)
}
 
/*********************************
        getPublicViews
*********************************/
void getPublicViews(string mName, Buffer resBuf)
{
        Module m = null
        string vn = ""
        string uName = ""
        bool noneFound = true
 
        m = read(mName, false)
 
        if (null m)
        {
                resBuf += "ERROR: Failed to open module " mName ".\n"
                return
        }
 
        (current ModuleRef__) = m
 
        for vn in views m do
        {
                if (isPublic(view vn, uName))
                {
                        resBuf += name(m) " has public view \"" vn "\" owned by " uName ".\n"
                        noneFound = false
                        
                        View v = view vn
                        unsetAll (v)    
                        set (v, control | delete, "") // give everyone control permissions
                }
        }
 
        if (noneFound)
        {
                resBuf += name(m) " does not have any public views.\n"
        }
 
        close(m)
}
 
/*********************************
        doRun
*********************************/
void doRun(DB db)
{
        Item i
        setempty(buf)
        int pCount = 0
        int pLimit = 0
 
        for i in current Folder do
        {
                if (type(i) != "Formal") continue
 
                pLimit++
        }
 
        if (pLimit == 0)
        {
                buf += "No modules found.\n"
        }
        else
        {
                //buf += pLimit " modules found.\n"
 
                if (!confirm("You are about to search for public views in " pLimit " modules\nAre you sure you want to continue?"))
                {
                        buf += "Command aborted by user.\n"
                }
                else
                {
                        progressStart(dbMain, "Checking modules", "Checking modules", pLimit)
 
                        for i in current Folder do
                        {
                                if (type(i) != "Formal") continue
 
                                pCount++
                                progressRange("Checking module " pCount " of " pLimit ".", pCount, pLimit)
 
                                getPublicViews(fullName(i), buf)
                        }
 
                        progressStop()
                }
        }
 
        set(dbeResults, buf)
}
 
/*********************************
        listPublicViews
*********************************/
void listPublicViews()
{
        dbMain = create(dbExplorer, "List Public Views", styleCentered|styleFloating)
 
        label(dbMain, "This utility allows you identify public views, and their owners, contained in modules below the current folder.")
 
        field(dbMain, "Folder:", fullName(current Folder), 50, true)
 
        dbeResults = text(dbMain, "Results:", "", 600, 150, true)
 
        apply(dbMain, "Run", doRun)
 
        realize(dbMain)
 
        show(dbMain)
}
 
/*********************************
        MAIN
*********************************/
listPublicViews()

I believe the rules are; in order of precedence:

  • "Custom" - There is an access-record other than the current user and the default access-records
  • "Private" - the default access-record is "None"
  • "Public" - the default access-record includes "R".


I assert that the "default" access record has name "Everyone else" in the GUI, and has null name "" using DXL.

I think that, for purposes of this script, we should ignore "Custom" views and define "Private" as being the default with "none".

If so then function isPublic() is wrong; reference to the "Administrator" is hopeless, and it should look like:

 

bool isPublic(View v, string &uName)
{
    AccessRec ar = null
        bool def = false
 
        for ar in v do
        {
                //if no user or group assigned to AR, then must be the default "Everyone else" group
                uName = username ar
                if(null uName) 
                {
                        if(getAccessRecord(ar) != "None"){def = true}
                }
        }
        return(def)
}


-Louie

 

Re: Public View
llandale - Wed Jan 09 16:56:51 EST 2013

llandale - Wed Jan 09 16:52:00 EST 2013

I believe the rules are; in order of precedence:

  • "Custom" - There is an access-record other than the current user and the default access-records
  • "Private" - the default access-record is "None"
  • "Public" - the default access-record includes "R".


I assert that the "default" access record has name "Everyone else" in the GUI, and has null name "" using DXL.

I think that, for purposes of this script, we should ignore "Custom" views and define "Private" as being the default with "none".

If so then function isPublic() is wrong; reference to the "Administrator" is hopeless, and it should look like:

 

bool isPublic(View v, string &uName)
{
    AccessRec ar = null
        bool def = false
 
        for ar in v do
        {
                //if no user or group assigned to AR, then must be the default "Everyone else" group
                uName = username ar
                if(null uName) 
                {
                        if(getAccessRecord(ar) != "None"){def = true}
                }
        }
        return(def)
}


-Louie

 

Incidentally, some version of DOORS v7x had a bug where when the Adminsitrator indeed made a view, that an AccessRecord for the "Administrator" was created. This created havok for Admins looking at views since they had no access to the Administrator's privaleged user account. I'm guessing the code you found was written in that version and feebly attempted to accomondate.

I note that since the Administrator has default RMCDA to EVERYTHING, there is no need nor should never be any AccessRecord named "Administrator". I wonder what it could possibly mean.

-Louie

Re: Public View
Tony_Goodman - Thu Jan 10 05:26:31 EST 2013

SystemAdmin - Wed Jan 09 09:43:24 EST 2013

Hello,

I found the below code on the internet and made modifications to it. Does anyone see logic errors? Thank you.

-Jim
 

// List Public Views
 
/*
    Lists public views found in modules.

        Reports public views found in modules together with the owner
        and their email address.

        24-MAY-2011             Tony Goodman
*/
 
pragma runLim, 0
 
DB  dbMain      = null
DBE dbeResults  = null
 
Buffer buf = create
 
/*********************************
        getAccessRecord
*********************************/
string getAccessRecord(AccessRec ar)
{
        string r = ((read ar)    ? "R" : "")
        string m = ((modify ar)  ? "M" : "")
        string c = ((create ar)  ? "C" : "")
        string d = ((delete ar)  ? "D" : "")
        string a = ((control ar) ? "A" : "")
 
        string accessStr =  r m c d a ""
 
        if (null accessStr){accessStr = "None"}
 
        return(accessStr)
}
 
/*********************************
        isPublic
*********************************/
bool isPublic(View v, string &uName)
{
        AccessRec ar = null
        int count = 0
        bool def = false
 
        for ar in v do
        {
                //if no user or group assigned to AR, then must be the default "Everyone else" group
                uName = username ar
 
        if(null uName) 
                {
                        uName = "Administrator"
 
            if(getAccessRecord(ar) != "None"){def = true}
                }
        }
 
        return(def)
}
 
/*********************************
        getPublicViews
*********************************/
void getPublicViews(string mName, Buffer resBuf)
{
        Module m = null
        string vn = ""
        string uName = ""
        bool noneFound = true
 
        m = read(mName, false)
 
        if (null m)
        {
                resBuf += "ERROR: Failed to open module " mName ".\n"
                return
        }
 
        (current ModuleRef__) = m
 
        for vn in views m do
        {
                if (isPublic(view vn, uName))
                {
                        resBuf += name(m) " has public view \"" vn "\" owned by " uName ".\n"
                        noneFound = false
                        
                        View v = view vn
                        unsetAll (v)    
                        set (v, control | delete, "") // give everyone control permissions
                }
        }
 
        if (noneFound)
        {
                resBuf += name(m) " does not have any public views.\n"
        }
 
        close(m)
}
 
/*********************************
        doRun
*********************************/
void doRun(DB db)
{
        Item i
        setempty(buf)
        int pCount = 0
        int pLimit = 0
 
        for i in current Folder do
        {
                if (type(i) != "Formal") continue
 
                pLimit++
        }
 
        if (pLimit == 0)
        {
                buf += "No modules found.\n"
        }
        else
        {
                //buf += pLimit " modules found.\n"
 
                if (!confirm("You are about to search for public views in " pLimit " modules\nAre you sure you want to continue?"))
                {
                        buf += "Command aborted by user.\n"
                }
                else
                {
                        progressStart(dbMain, "Checking modules", "Checking modules", pLimit)
 
                        for i in current Folder do
                        {
                                if (type(i) != "Formal") continue
 
                                pCount++
                                progressRange("Checking module " pCount " of " pLimit ".", pCount, pLimit)
 
                                getPublicViews(fullName(i), buf)
                        }
 
                        progressStop()
                }
        }
 
        set(dbeResults, buf)
}
 
/*********************************
        listPublicViews
*********************************/
void listPublicViews()
{
        dbMain = create(dbExplorer, "List Public Views", styleCentered|styleFloating)
 
        label(dbMain, "This utility allows you identify public views, and their owners, contained in modules below the current folder.")
 
        field(dbMain, "Folder:", fullName(current Folder), 50, true)
 
        dbeResults = text(dbMain, "Results:", "", 600, 150, true)
 
        apply(dbMain, "Run", doRun)
 
        realize(dbMain)
 
        show(dbMain)
}
 
/*********************************
        MAIN
*********************************/
listPublicViews()

You broke my script!

The logic behind the isPublic function is that public views have exactly two access records. One is for READ for Everyone Else, and the other is RMCDA for the owner.
 

/*********************************  
    isPublic  
*********************************/ 
bool isPublic(View v, string &uName, string &uEmail)  
{  
    AccessRec ar = null 
    User u = null 
    int count = 0  
    bool def = false 
   
    for ar in v do 
    {  
        count++  
    }  
   
    if (count == 2)  
    {  
        for ar in v do 
        {  
            if (getAccessRecord(ar) == "R")  
            {  
                def = true 
            }  
            else if (getAccessRecord(ar) == "RMCDA")  
            {  
                uName = username ar  
   
                if (uName "" != "")  
                {  
                    u = find(uName)  
                }  
   
                if (!null u)  
                {  
                    uEmail = u.email 
                }  
            }  
        }  
   
        return(def && !null u)  
    }  
   
    return(false)  
}

 


Tony Goodman, www.smartdxl.com

 

Re: Public View
SystemAdmin - Thu Jan 10 12:53:39 EST 2013

Tony_Goodman - Thu Jan 10 05:26:31 EST 2013

You broke my script!

The logic behind the isPublic function is that public views have exactly two access records. One is for READ for Everyone Else, and the other is RMCDA for the owner.
 

/*********************************  
    isPublic  
*********************************/ 
bool isPublic(View v, string &uName, string &uEmail)  
{  
    AccessRec ar = null 
    User u = null 
    int count = 0  
    bool def = false 
   
    for ar in v do 
    {  
        count++  
    }  
   
    if (count == 2)  
    {  
        for ar in v do 
        {  
            if (getAccessRecord(ar) == "R")  
            {  
                def = true 
            }  
            else if (getAccessRecord(ar) == "RMCDA")  
            {  
                uName = username ar  
   
                if (uName "" != "")  
                {  
                    u = find(uName)  
                }  
   
                if (!null u)  
                {  
                    uEmail = u.email 
                }  
            }  
        }  
   
        return(def && !null u)  
    }  
   
    return(false)  
}

 


Tony Goodman, www.smartdxl.com

 

if you create the view as the "Administrator" you only have one access record. (Everyone R)

-Jim

Re: Public View
Chris Annal - Mon Jul 28 11:40:56 EDT 2014

Tony_Goodman - Thu Jan 10 05:26:31 EST 2013

You broke my script!

The logic behind the isPublic function is that public views have exactly two access records. One is for READ for Everyone Else, and the other is RMCDA for the owner.
 

/*********************************  
    isPublic  
*********************************/ 
bool isPublic(View v, string &uName, string &uEmail)  
{  
    AccessRec ar = null 
    User u = null 
    int count = 0  
    bool def = false 
   
    for ar in v do 
    {  
        count++  
    }  
   
    if (count == 2)  
    {  
        for ar in v do 
        {  
            if (getAccessRecord(ar) == "R")  
            {  
                def = true 
            }  
            else if (getAccessRecord(ar) == "RMCDA")  
            {  
                uName = username ar  
   
                if (uName "" != "")  
                {  
                    u = find(uName)  
                }  
   
                if (!null u)  
                {  
                    uEmail = u.email 
                }  
            }  
        }  
   
        return(def && !null u)  
    }  
   
    return(false)  
}

 


Tony Goodman, www.smartdxl.com

 

Hi Tony,

Your scripts are excellent and I've used many of them for various tasks. I did discover one corner case where this script produces an error. Apparently, if a user created a view and that user is no longer in the database, the script will toss an error at the line

u = find (uName)

and later lines in the script that rely on that line. Should their be a break statement for that corner case?

Re: Public View
llandale - Mon Jul 28 16:44:58 EDT 2014

Chris Annal - Mon Jul 28 11:40:56 EDT 2014

Hi Tony,

Your scripts are excellent and I've used many of them for various tasks. I did discover one corner case where this script produces an error. Apparently, if a user created a view and that user is no longer in the database, the script will toss an error at the line

u = find (uName)

and later lines in the script that rely on that line. Should their be a break statement for that corner case?

Run the script as the "Administrator".

Seems to me you'd need to do that anyway, adding your "DB Admins" group to all the views.  And folders modules that are not Inherited.

Re: Public View
ChrisAnnal - Mon Jul 28 17:15:37 EDT 2014

llandale - Mon Jul 28 16:44:58 EDT 2014

Run the script as the "Administrator".

Seems to me you'd need to do that anyway, adding your "DB Admins" group to all the views.  And folders modules that are not Inherited.

You're right about a script that intends to modify the access to a View (if the user who created it didn't bother to make any changes to the default access), However, this script is simply listing those views that fall into that category - so you don't have to be an Administrator to run it.

In other words, a user named "vCreator" created a Public View named "MyView". The default access to that view is:

vCreator = RMCDA

Everyone Else = R

...and you have to be an Administrator in order to change that access if user vCreator is no longer in the database.

What I'm saying is that if user vCreator is no longer in the database, the script fails at the line:

u = find (uName)

This is regardless of who runs the script.

Re: Public View
Chris Annal - Tue Aug 05 11:14:02 EDT 2014

ChrisAnnal - Mon Jul 28 17:15:37 EDT 2014

You're right about a script that intends to modify the access to a View (if the user who created it didn't bother to make any changes to the default access), However, this script is simply listing those views that fall into that category - so you don't have to be an Administrator to run it.

In other words, a user named "vCreator" created a Public View named "MyView". The default access to that view is:

vCreator = RMCDA

Everyone Else = R

...and you have to be an Administrator in order to change that access if user vCreator is no longer in the database.

What I'm saying is that if user vCreator is no longer in the database, the script fails at the line:

u = find (uName)

This is regardless of who runs the script.

I found a workaround that works for my purposes, anyway. I just created a string to catch "uName" instead of looking for a user from the database. Since the email portion is also using a user from the database, I worked around that by hard-coding the email address. It assumes "ViewOwner" is the name of the user without actually verifying it in the database. This avoids the error when a user has been disabled or purged from the database...

*********************************/
bool isPublic(View v, string &uName, string &uEmail)
{
 AccessRec ar = null
 string ViewOwner = null //added to avoid error in "u.name" if user is no longer in database.
 int count = 0
 bool def = false

 for ar in v do
 {
  count++
 }

 if (count == 2)
 {
  for ar in v do
  {
   if (getAccessRecord(ar) == "R")
   {
    def = true
   }
   else if (getAccessRecord(ar) == "RMCDA")
   {
    uName = username ar

    if (uName "" != "")
    {
     ViewOwner = uName "" //changed from "u.name" to string "ViewOwner" since users no longer in DB caused errors
    }

    if (!null u)
    {
     uEmail = ViewOwner"@yourcompany.com" //modified to allow for users no longer in database (error now caught by Outlook)
    }
   }
  }

  return(def && !null u)
 }

 return(false)
}

Re: Public View
llandale - Wed Aug 06 13:53:05 EDT 2014

ChrisAnnal - Mon Jul 28 17:15:37 EDT 2014

You're right about a script that intends to modify the access to a View (if the user who created it didn't bother to make any changes to the default access), However, this script is simply listing those views that fall into that category - so you don't have to be an Administrator to run it.

In other words, a user named "vCreator" created a Public View named "MyView". The default access to that view is:

vCreator = RMCDA

Everyone Else = R

...and you have to be an Administrator in order to change that access if user vCreator is no longer in the database.

What I'm saying is that if user vCreator is no longer in the database, the script fails at the line:

u = find (uName)

This is regardless of who runs the script.

I check for the existence first with one or both of these:

bool existsGroup(string name)

bool existsUser(string name)

You can also trap the error:

string Name = "zz"
noError()
User u = find(Name)
string ErrMess = lastError()
if (!null ErrMess) //
then print (null u) "\t" Name "\tNo such user\t[" ErrMess "]"
else
{} 

Curious, "u" comes back non-null so you need ErrMess.

-Louie